package org.sdp.pearproject.controller;


import org.sdp.pearproject.controller.custom.*;
import org.sdp.pearproject.dto.request.*;
import org.sdp.pearproject.dto.response.*;

import java.util.List;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName: DepartmentController
 * @Description:
 * @Author: SDP
 * @Date: 2022-07-15
 * @Version: 1.0
 * Table: pear_department
 * Comment:
 * 部门表
 */
@RestController
@RequestMapping(value = "/department")
public class DepartmentController extends DepartmentCustomController {
    static {
        addRequestClass("department", "add", "departmentController", DepartmentController.class, DepartmentAddRequest.class);
        addRequestClass("department", "add_encrypt", "departmentController", DepartmentController.class, DepartmentAddRequest.class);

        addRequestClass("department", "update", "departmentController", DepartmentController.class, DepartmentUpdateRequest.class);
        addRequestClass("department", "update_encrypt", "departmentController", DepartmentController.class, DepartmentUpdateRequest.class);

        addRequestClass("department", "delete", "departmentController", DepartmentController.class, DepartmentDeleteRequest.class);
        addRequestClass("department", "delete_encrypt", "departmentController", DepartmentController.class, DepartmentDeleteRequest.class);

        addRequestClass("department", "query", "departmentController", DepartmentController.class, DepartmentQueryRequest.class);
        addRequestClass("department", "query_encrypt", "departmentController", DepartmentController.class, DepartmentQueryRequest.class);

        addRequestClass("department", "list", "departmentController", DepartmentController.class, DepartmentQueryRequest.class);
        addRequestClass("department", "list_encrypt", "departmentController", DepartmentController.class, DepartmentQueryRequest.class);

        addRequestClass("department", "count", "departmentController", DepartmentController.class, DepartmentQueryRequest.class);
        addRequestClass("department", "count_encrypt", "departmentController", DepartmentController.class, DepartmentQueryRequest.class);

        addRequestClass("department", "stat", "departmentController", DepartmentController.class, DepartmentQueryRequest.class);
        addRequestClass("department", "stat_encrypt", "departmentController", DepartmentController.class, DepartmentQueryRequest.class);

    }

    @PostMapping("/add")
    public Integer addDepartment(@MixRequestBody DepartmentAddRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("department", "add", request, callFromEncrypt);
        return super.addDepartment(request);
    }

    @PostMapping("/add_encrypt")
    public String addDepartmentEncrypt(@MixRequestBody String strRequest) throws Exception {
        DepartmentAddRequest request = (DepartmentAddRequest) super.decrypt("department", "add_encrypt", strRequest, DepartmentAddRequest.class);
        Integer result = addDepartment(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/update")
    public Integer updateDepartment(@MixRequestBody DepartmentUpdateRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("department", "update", request, callFromEncrypt);
        return super.updateDepartment(request);
    }

    @PostMapping("/update_encrypt")
    public String updateDepartmentEncrypt(@MixRequestBody String strRequest) throws Exception {
        DepartmentUpdateRequest request = (DepartmentUpdateRequest) super.decrypt("department", "update_encrypt", strRequest, DepartmentUpdateRequest.class);
        Integer result = updateDepartment(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/delete")
    public Integer deleteDepartment(@MixRequestBody DepartmentDeleteRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("department", "delete", request, callFromEncrypt);
        return super.deleteDepartment(request);
    }

    @PostMapping("/delete_encrypt")
    public String deleteDepartmentEncrypt(@MixRequestBody String strRequest) throws Exception {
        DepartmentDeleteRequest request = (DepartmentDeleteRequest) super.decrypt("department", "delete_encrypt", strRequest, DepartmentDeleteRequest.class);
        Integer result = deleteDepartment(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/query")
    public DepartmentQueryResponse queryDepartment(@MixRequestBody DepartmentQueryRequest request, Integer callFromEncrypt) throws Exception {
      super.fixRequest("department", "query", request, callFromEncrypt);
      return super.queryDepartment(request);
    }

    @PostMapping("/query_encrypt")
    public String queryDepartmentEncrypt(@MixRequestBody String strRequest) throws Exception {
        DepartmentQueryRequest request = (DepartmentQueryRequest) super.decrypt("department", "query_encrypt", strRequest, DepartmentQueryRequest.class);
        DepartmentQueryResponse result = queryDepartment(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/list")
    public List<DepartmentQueryResponse> listDepartment(@MixRequestBody DepartmentQueryRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("department", "list", request, callFromEncrypt);
        if (super.needTotal("department", "list", request)) {
            super.setTotal("department", "list", request, super.countDepartment(request));
        }
        return super.listDepartment(request);
    }

    @PostMapping("/list_encrypt")
    public String listDepartmentEncrypt(@MixRequestBody String strRequest) throws Exception {
        DepartmentQueryRequest request = (DepartmentQueryRequest) super.decrypt("department", "list_encrypt", strRequest, DepartmentQueryRequest.class);
        List<DepartmentQueryResponse> result = listDepartment(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/count")
    public Integer countDepartment(@MixRequestBody DepartmentQueryRequest request, Integer callFromEncrypt) throws Exception {
      super.fixRequest("department", "count", request, callFromEncrypt);
      return super.countDepartment(request);
    }


    @PostMapping("/count_encrypt")
    public String countDepartmentEncrypt(@MixRequestBody String strRequest) throws Exception {
        DepartmentQueryRequest request = (DepartmentQueryRequest) super.decrypt("department", "count_encrypt", strRequest, DepartmentQueryRequest.class);
        Integer result = countDepartment(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/stat")
    public BaseStatResponse statDepartment(@MixRequestBody DepartmentQueryRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("department", "stat", request, callFromEncrypt);
        return super.statDepartment(request);
    }

    @PostMapping("/stat_encrypt")
    public String statDepartmentEncrypt(@MixRequestBody String strRequest) throws Exception {
        DepartmentQueryRequest request = (DepartmentQueryRequest) super.decrypt("department", "stat_encrypt", strRequest, DepartmentQueryRequest.class);
        BaseStatResponse result = statDepartment(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }


}
